package cn.kgm.makeGodV2.ruleEngine;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-24 17:58
 * @Description: cn.kgm.makeGodV2.ruleEngine.AdvancedEventExample
 */
public class AdvancedEventExample {
    public static void main(String[] args) {
        RuleEngine ruleEngine = RuleEngine.getInstance();
        ruleEngine.registerRule(new RealmCheckRule());
        ruleEngine.registerRule(new SingleItemCheckRule());
        ruleEngine.registerRule(new AndConditionRule());
        ruleEngine.registerRule(new OrConditionRule());
        // 复杂条件：金丹期以上 AND (具备避毒丹2个 OR 飞行符1个) AND 具备疗伤药3个
        ConditionConfig advancedCondition = ConditionConfig.and(
                ConditionConfig.atomic("REALM_CHECK", "金丹期"), // 境界要求
                ConditionConfig.or( // 物品要求（或关系）
                        ConditionConfig.atomic("SINGLE_ITEM_CHECK",
                                Collections.singletonMap("避毒丹", 2)),
                        ConditionConfig.atomic("SINGLE_ITEM_CHECK",
                                Collections.singletonMap("飞行符", 1))
                ),
                ConditionConfig.atomic("SINGLE_ITEM_CHECK", // 额外要求
                        Collections.singletonMap("疗伤药", 3))
        );

        RuleContext context = new RuleContext();
        context.setParam("playerRealm", "元婴期"); // 满足境界要求
        Map<String, Integer> playerItems = new HashMap<>();
        playerItems.put("避毒丹", 3);
        playerItems.put("飞行符", 1);
        playerItems.put("疗伤药", 5);
        context.setParam("playerItems", playerItems);
        context.setParam("subConditions", advancedCondition.getConditions());

        RuleResult<Boolean> result = ruleEngine.executeRule("AND", context);

        System.out.println("=== 高级复杂条件检查 ===");
        System.out.println("条件: 金丹期以上 AND (避毒丹2个 OR 飞行符1个) AND 疗伤药3个");
        System.out.println("玩家境界: 元婴期");
        System.out.println("玩家物品: " + playerItems);
        System.out.println("执行结果: " + result.getMessage());
        System.out.println("是否满足: " + result.getData());
    }
}
